package com.linhngua.code.gwt.spring;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;

import com.linhngua.code.data.people.Customer;
import com.linhngua.code.data.people.Owner;
import com.linhngua.code.data.people.User;
import com.linhngua.code.data.shop.Shop;
import com.linhngua.code.data.shop.Item;
import com.linhngua.code.hibernate.config.Database;
import com.linhngua.code.hibernate.config.DomainClass;

@Configuration
@Profile({ "dev" })
public class DatabaseSpring {
	
	@Autowired
	Environment	environment;
	
	@Bean
	public DomainClass domainClass() {

		DomainClass domainClass = new DomainClass(Customer.class, User.class,
				Owner.class, Shop.class, Item.class);
		
		return domainClass;
	}
	
	@Bean
	Database database() {

		String jdbcUrl = environment.getProperty("db.jdbc.url");
		String userName = environment.getProperty("db.username");
		String password = environment.getProperty("db.password");
		String validationQuery = environment.getProperty("db.validation.query");
		Database database = new Database(jdbcUrl, userName, password,
				validationQuery);
		
		return database;
	}
}
